 package cn.itcast.websocket;

import javax.websocket.OnClose;
import javax.websocket.OnMessage;
import javax.websocket.OnOpen;
import javax.websocket.Session;
import javax.websocket.server.PathParam;
import javax.websocket.server.ServerEndpoint;
import java.io.IOException;

@ServerEndpoint("/websocket/{uid}")
public class MyWebSocket {
    @OnOpen
    public void onOpen(Session session, @PathParam(value = "uid") String uid) throws IOException {
        System.out.println("已经连接"+session);
        //给客户端相应
        session.getBasicRemote().sendText("欢迎"+uid+"扑街");
    }

    @OnClose
    public  void onClose(Session session){
        System.out.println("我关闭了"+session);

    }

    @OnMessage
    public void onMessage(String message,Session session) throws IOException, InterruptedException {
        System.out.println("收到客户端发来的消息"+message);

        Thread.sleep(200);

        //给你点反应
        session.getBasicRemote().sendText("收到消息了");

    }

}
